package cn.jofei.common.enums;

import java.util.Arrays;

/**
 * 请求类型
 *
 * @author Jofei Bao
 * @version ngbao v1.0.1
 * @date 2022年02月28日 20:47
 */
public enum Types {
    //客户端信息
    TCP("TCP"), WEB("WEB"),
    //心跳检测
    PING("PING"), PONG("PONG"),
    //注册信息
    HTTP_REG("HTTP_REG"), TCP_REG("TCP_REG"), REG_RESPONSE("REG_RESPONSE"),
    //http请求
    HTTP_NOTIFY("HTTP_NOTIFY"), HTTP_RESPOND("HTTP_RESPOND"),
    //tcp请求
    TCP_NOTIFY("TCP_NOTIFY"), TCP_RESPOND("TCP_RESPOND"),
    UNKNOWN("UNKNOWN")
    ;

    private final String type;

    Types(String type) {
        this.type = type;
    }

    public String value() {
        return type;
    }

    public boolean eq(String s) {
        if (s == null) return false;
        return type.equals(s);
    }

    public boolean eq(Types s) {
        if (s == null) return false;
        return type.equals(s.type);
    }

    public static Types getType(String s){
        return Arrays.stream(values()).filter(e -> e.eq(s)).findFirst().orElse(UNKNOWN);
    }

    @Override
    public String toString() {
        return type;
    }
}
